import { onMounted, onUnmounted } from "vue";

export const useCreateUEInstance = (options, cb) => {
  onMounted(() => {
    if (!options.dom) return console.log("dom不存在");
    if (!options.url) return console.log("url不存在");
    const dom = document.getElementById(options.dom);
    window.fpstream = new Fpstream(
      dom,
      options.url, //地址由推流平台中，已启动的实例中复制过来
      {
        //额外的参数
        HoveringMouse: options.HoveringMouse || true, //显示前端鼠标
      }
    );
    //执行连接方法
    fpstream.connect(cb);
  });
  const destroy = () => {
    //销毁实例
    window.fpstream && window.fpstream.disconnect();
    window.fpstream = null;
  };
  onUnmounted(() => {
    destroy();
  });
  return { destroy };
};
